<%@ page contentType="text/html;charset=utf-8" language="java" pageEncoding="utf-8"%>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFSheet" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFRow" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCell" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFDateUtil" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFCellStyle" %>
<%@ page import="java.util.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>Show Excel</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  <%
  	SimpleDateFormat sdf=new SimpleDateFormat("MM/dd");
  	HSSFWorkbook wb=(HSSFWorkbook)request.getAttribute("workbook");
  	HSSFSheet sheet=wb.getSheetAt(0);
  	int begin=sheet.getFirstRowNum();
  	int end=sheet.getLastRowNum();
   %>
   <%=wb.getSheetName(0)%><br>
	<table border="1">
		<%for(int i=begin;i<=end;i++){
			HSSFRow row=sheet.getRow(i);
			if(row!=null){
		%>
		<tr>
			<%
				int firstCell=row.getFirstCellNum();
				int lastCell=row.getLastCellNum();
				Object result=null;
				for(int j=firstCell;j<lastCell;j++){
					HSSFCell cell=row.getCell(j);
					if(cell==null){
					%>
						<td>&nbsp;</td>
					<%
						continue;
					}else if(cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC){
						if(HSSFDateUtil.isCellDateFormatted(cell)){
							Date date=(Date)cell.getDateCellValue();
							result=sdf.format(date);
						}else{
							result=cell.getNumericCellValue();
						}
					}else if(cell.getCellType()==HSSFCell.CELL_TYPE_STRING){
						result=cell.getRichStringCellValue();
					}else{
						result="";
					}
			 %>
			 	<td><%=result %>&nbsp;</td>
			 <%} %>
		</tr>
		<%}
		}
		%>
	</table>
  </body>
</html>
